package com.wyk.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.wyk.bean.Payment;
import com.wyk.common.Result;
import com.wyk.hanlder.CustomerBlockHanlder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author WangYuKai
 * @Date 2022/7/31
 * @apiNote
 */
@RestController
public class RateLimitController {

    @GetMapping("/byResource")
    @SentinelResource(value = "byResource",blockHandler = "hanlderException")
    public Result byResource(){
        return new Result(200,"按照资源名测试OK",new Payment(2022L,"serial001"));
    }

    public Result hanlderException(BlockException exception){
        return new Result(444,exception.getClass().getCanonicalName() + "\t服务不可用");
    }


    @GetMapping("/customer/byResource")
    @SentinelResource(value = "contosumerResource",blockHandlerClass = CustomerBlockHanlder.class,
            blockHandler = "hanlderException2")
    public Result ContosumerResource(BlockException exception){
        return new Result(200,"正常的访问整机兜底方案OK");
    }
}
